<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="example">
    <my-component></my-component>
</div>
<script src="../js/vue.min.js"></script>
<script>
    //向子组件传递数据
    //省略extend方法，vue内部调用
    Vue.component('my-component', {
        //模板里不支持驼峰的属性写法，需要转换为‘-’连接的属性写法
        data: function () {
            return {
                parentMsg: 'prop传值',
                testjson: {a: "789954", b: "sdf"}
            }
        },
        template: '<div>' + '<input v-model="parentMsg">' + '<br>' + '<child-component :gedata="parentMsg" :jsondata="testjson" ></child-component><child-component2></child-component2>' + '</div>',
        components: {
            'child-component': {
//                props: ['gedata', 'jsondata'],//不设置默认值
                props: {gedata: {required: true}, jsondata: {default: "我是默认值！"}}, //设置默认值

                template: '<div>{{gedata}}-{{jsondata}}</div>'
            },
            'child-component2': {
                template: '<div>我是末班二号</div>'
            }
        }
    });
    // 创建根实例1
    new Vue({
        el: '#example',
        data: {
            a: 1
        },
        created: function () {
            // `this` 指向 vm 实例  vm==data
            console.log('a is: ' + this.a)
        }
    });
</script>
</body>
</html>